package com.speaktoitcookbook.dao.proxy;

import java.sql.Connection;
import java.util.List;

import com.speaktoitcookbook.bean.Cookbook;
import com.speaktoitcookbook.bean.Material;
import com.speaktoitcookbook.dao.IMaterialDao;
import com.speaktoitcookbook.dao.impl.MaterialDaoImpl;
import com.speaktoitcookbook.db.Database;

/**
 * 菜谱原料数据操作代理类
 * 
 * @author Administrator
 * 
 */
public class MaterialDaoProxy implements IMaterialDao {
    private Connection conn;
    private IMaterialDao dao;

    public MaterialDaoProxy() {
        this.conn = Database.getInstance().getConnection();
        this.dao = new MaterialDaoImpl(conn);
    }

    @Override
    public boolean doCreate(Material material) {
        boolean result = false;
        if (null != material) {
            result = dao.doCreate(material);
        }
        Database.close(conn);
        return result;
    }

    @Override
    public boolean doUpdate(Material material) {
        boolean result = false;
        if (null != material) {
            result = dao.doUpdate(material);
        }
        Database.close(conn);
        return result;
    }

    @Override
    public boolean doDelete(long cookbookID, String name) {
        boolean result = false;
        if ((cookbookID > 0) && (null != name && !name.isEmpty())) {
            result = dao.doDelete(cookbookID, name);
        }
        Database.close(conn);
        return result;
    }

    @Override
    public List<Material> getMaterial(long cookbookID) {
        List<Material> result = null;
        if (cookbookID > 0) {
            result = dao.getMaterial(cookbookID);
        }
        Database.close(conn);
        return result;
    }

    @Override
    public List<Cookbook> getCookbook(String name) {
        List<Cookbook> result = null;
        if (null != name && !name.isEmpty()) {
            result = dao.getCookbook(name);
        }
        Database.close(conn);
        return result;
    }
}
